/** 封装可以显示http图片的组件 */
class ImageComponent extends eui.Image {
	public constructor() {
		super();
	}

	private loader: egret.ImageLoader;

	protected childrenCreated() {
		this.loader = new egret.ImageLoader();
		this.loader.addEventListener(egret.Event.COMPLETE, this.loadCompleteHandler, this);
		this.loader.crossOrigin = "Anonymous";
	}

	private loadCompleteHandler() {
		let texture = new egret.Texture();
		texture._setBitmapData(this.loader.data);

		this.source = texture;
	}

	public loadImg(url: string, def:string = "img_default_png") {
		if (!!url && url.indexOf("http") > -1) {
			this.loader.load(url);
		} else {
			this.source = def;
		}
	}
}